﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BusinessObjects.BO_GetObjects;
using BussinessObjects;
using BusinessObjects;
using LibraryO2S;
using BusinessObjects.BO_Actions.Members;
using System.Collections.Generic;
using Entity.StoreProcedure;

public partial class controls_admin_Members : Pages_Base
{
    private DataTable objDT;
    protected void Page_Load(object sender, EventArgs e)
    {
        base.removeHGC(divMessage);
        base.removeHGC(divResult);
        if (!IsPostBack)
            loadData();
    }
    private void loadDialog()
    {

    }
    protected void loadData()
    {
        try
        {
            objDT = BO_Members.SelectWithPaged(base.Cur_page, base.Page_size, 1);
            bindRepeater(rptData, objDT, pagerContainer, divMessage);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void btnDel_Click(object sender, EventArgs e)
    {
        string del_list = hdfID.Value;
        string[] sp_list = del_list.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        BOMembers_Delete _action = new BOMembers_Delete();
        usp_Members_Delete _entity;
        List<usp_Members_Delete> _listData = new List<usp_Members_Delete>();
        foreach (string per in sp_list)
        {
            _entity = new usp_Members_Delete();
            _entity.MEMBER_ID = Convert.ToInt32(per);
            _listData.Add(_entity);
        }
        if (_action.ExecuteListDataAndReturnBooleanValue(_listData))
            divMessage.InnerHtml = O2S_Message.Success("Thông Báo", "Thực hiện thành công.");
        else
            divMessage.InnerHtml = O2S_Message.Error("Lỗi", "Chưa thực hiện được !");
        loadData();
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string keyword = txtSearch.Value.Trim();
        if (keyword != null && !keyword.Equals("") && !keyword.Equals("Hãy nhập từ khóa !"))
            Response.Redirect("default.aspx?module=members&k_w=" + keyword);
    }
    protected void rptData_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        try
        {
            base.OpenConnection();
            int e_id = Convert.ToInt32(e.CommandArgument);
            if (e.CommandName.Equals("dialog"))
            {
                DataRow row = BO_Members.Search(e_id).Rows[0];
                hdfDialog.Value = "1";
                ltrAddress.Text = row["ADDRESS"].ToString();
                ltrEmail.Text = row["EMAIL"].ToString();
                ltrFax.Text = row["FAX"].ToString();
                ltrFullName.Text = row["FULL_NAME"].ToString();
                ltrMemberCode.Text = row["MEMBER_CODE"].ToString();
                ltrMonney.Text = row["LEFT_MONEY"].ToString();
                ltrPhone.Text = row["MOBILE"].ToString();
                ltrUserName.Text = row["USER_NAME"].ToString();
            }
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = O2S_Message.Error("Lỗi", "Phát hiện lỗi: <br />" + ex.Message);
        }
        finally { base.CloseConnection(); }
    }
}
